home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1991 / Feb 91 / MacApp.Tech$ 2⁄15⁄91 / 2922-overloading '=' oper-Feb91 < prev    next >
Encoding:
Text File  |  1991-03-06  |  1.5 KB  |  58 lines  |  [TEXT/GEOL]

  1. Item    6393689                         11-Feb-91        09:08PST
  2.  
  3. From:   CHANDLER1                       Chandler, Dick
  4.  
  5. To:     MACAPP.TECH$                    MacApp Technical
  6.  
  7. ------------------------------------------------------------------------------
  8.  
  9. Sub:    overloading '=' operator
  10.  
  11. I'm having trouble with overloading the '=' operator.
  12.  
  13. I think my overload is written correctly, but its never being called.
  14.  
  15. I declare to 'bars' which are music objects with:
  16.  
  17. The C++ compiler is coping the address of bar1 into bar2
  18.  
  19.         TBar   *bar1, *bar2;
  20.  
  21. Then I instantiate them with the following call:
  22.  
  23.  
  24.         bar1 = new TBar();
  25.         bar2 = new TBar();
  26.  
  27. After filling bar1 with note objects I call:
  28.  
  29.         bar2 = bar1;
  30.  
  31. Before this call both objects have different pointers, after the call they both
  32. have the pointer that bar1 had oringinally.  So it seems the compiler is simply
  33. coping the pointer.  The overloaded '=' operator is never called.
  34.  
  35. I want to keep them as pointers and create them on the fly, any suggestions or
  36. observations on something wrong!?!?
  37.  
  38. Thanks -  Dick
  39.  
  40. enclosed is the operator function which isn't being called.
  41. /*************************************************************************
  42. *  NAME:   +  overload for TBar
  43. *
  44. *  FUNCTION:   TBar = TBar
  45. **************************************************************************/
  46. TBar& TBar::operator = (TBar& sourceBar)
  47. {
  48.  
  49.    short loop = 0;
  50.    while( sourceBar.fNotes[loop] && loop<kMaxNotes )
  51.    {
  52.    this->fNotes[loop] = sourceBar.fNotes[loop];
  53.    }
  54.    return  *this;
  55.  
  56. }
  57.  
  58.